#ifndef MYSQL_H
#define MYSQL_H

#include <QWidget>
#include <QSqlDatabase>
#include <QtCore/QMutex>
#include "beans/designdatabean.h"
#include "beans/userinfobean.h"

class MySql
{
public:
    MySql(QString& Dir);
    ~MySql();

private:
    bool CreateConnection();      //创建数据库连接//
    bool isDirExist();            //路径是否存在//

    QString connectionName;       //连接名称//
    QString dbDir;                //.db文件路径//
    QSqlDatabase db;
    QMutex mutex;                 //多线程资源访问控制//
public:
    void closeDb();               //关闭数据库//

    bool UserInsert(UserInfoBean& userBean);
    bool DesignDataInsert(designDataBean& InputImgInfo);                   //插入//
    bool DesignDataDelete(QString name);                               //删除//
    QList<designDataBean> QueryAllDesignData();
    bool DesignDataSelect(QString name, designDataBean &dataBean);
    bool DesignDataQueryBy(QString name);
private:
    void  requestAccessToken(void);                           //加锁//
    void  releaseAccessToken(void);                           //解锁//

};

#endif // MYSQL_H
